import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QHBoxLayout
from PyQt5.QtGui import QPixmap, QImage, QPalette
from PyQt5.QtCore import QTimer, QTime,Qt,QDateTime
class MyWindow(QWidget):
    def __init__(self):
        super().__init__()

        # 设置窗口大小
        self.setWindowTitle("布局示例")
        self.setGeometry(100, 100, 800, 600)

        # 设置布局
        self.main_layout = QVBoxLayout(self)

        # 创建顶部区域
        self.top_layout = QHBoxLayout()

        # 设置背景图
        self.background_label = QLabel(self)
        background_pixmap = QPixmap("views/assets/header_bg.png")  # 替换为你的背景图路径
        self.background_label.setPixmap(background_pixmap)
        
        self.background_label.setScaledContents(True)

        # 创建一个浮动图片
        self.floating_image_label = QLabel(self)
        floating_pixmap = QPixmap("views/assets/header_title.png")  # 替换为你的浮动图片路径
        self.floating_image_label.setPixmap(floating_pixmap)

        # 创建一个时间标签
        self.time_label = QLabel(self)
        self.time_label.setStyleSheet("color: white; font-size: 18px;")
        self.update_time()

        # 使用 QTimer 每秒更新时间
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_time)
        self.timer.start(1000)

        # 设置布局
        self.top_layout.addWidget(self.time_label)
        self.top_layout.addWidget(self.floating_image_label, alignment=Qt.AlignCenter)
        #self.top_layout.addWidget(self.floating_image_label, 0, 1, Qt.AlignCenter)  # 使图片居中
        self.main_layout.addLayout(self.top_layout)

    def update_time(self):
        current_time = QTime.currentTime().toString("HH:mm:ss")
        self.time_label.setText(current_time)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())
